package com.qingcheng.controller;


import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.goods.Spu;
import com.qingcheng.pojo.order.Order;
import com.qingcheng.pojo.order.Orders;
import com.qingcheng.service.OrderService;
import com.qingcheng.util.JwtUtils;
import com.qingcheng.vo.goods.OrderListVo;
import com.qingcheng.vo.goods.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.HttpConstraintElement;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/findAll")
    public List<Order> findAll(){
        return orderService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Order> findPage(int page, int size){
        return orderService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String,Object> searchMap){
        return orderService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  orderService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Orders findById(String id){
        return orderService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Order order){
        orderService.add(order);
        return new Result(200,"添加成功",null);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Order order){
        orderService.update(order);
        return new Result(200,"修改成功",null);
    }

    @GetMapping("/delete")
    public Result delete(String id){
        orderService.delete(id);
        return new Result(200,"删除成功",null);
    }

    @GetMapping("/selectAllDetermineOrder")
    public Result selectAllDetermineOrder(@RequestBody Map<String,Object> searchMap,int page, int size){
        return new Result(200,"查询成功",orderService.selectAllDetermineOrder(searchMap,page,size));
    }

    @GetMapping("/selectCount")
    public Result selectCount(){
        return new Result(200,"统计成功",orderService.selectCount());
    }

    @PostMapping("/findByOids")
    public Result findByOids(@RequestBody Map<String,Object> searchMap) {
        return new Result(200,"查询成功",orderService.findByOids(searchMap));
    }

    @PostMapping("/batchSend")
    public Result batchSend (@RequestBody List<Order> orders) {
        orderService.batchSend(orders);
        return new Result(200,"发货成功","");
    }

    @GetMapping("/mergeOrders")
    public Result mergeOrders(String orderId1,String orderId2){
        orderService.mergeOrders(orderId1,orderId2);
        return new Result(200,"合并成功","");
    }

    @PostMapping("/splitOrders")
    public Result splitOrders(@RequestBody List<Map> map){
        orderService.splitOrders(map);
        return new Result(200,"拆分成功","");
    }

    @GetMapping("/lookOrderDetails")
    public Result lookOrderDetails(String id){
        return new Result(200,"查询成功",orderService.findOrderDetails(id));
    }

    @GetMapping("/determineOrder")
    public Result determineOrder(String id){
        orderService.determineOrder(id);
        return  new Result(200,"确认收货成功","");
    }

    @GetMapping("/determineOrde2r/{ids}")
    public Result determineOrde2r(@PathVariable("ids") List<String> ids){
        orderService.determineOrde2(ids);
        return  new Result(200,"确认收货成功","");
    }

    @GetMapping("/returnOrderItemService")
    public List<Map> returnOrderItemService(String orderId){
        return this.orderService.returnOrderItemService(orderId);
    }

    //查询用户订单
    @PostMapping("/service/getbyorder/{username}")
    public List<Order> selectOrderList(@PathVariable("username") String username){
        return orderService.selectOrderList(username);
    }


    @PostMapping("/saveOrder")
    public Map<String,Object> saveOrder(@RequestBody Order order, String username){
        order.setUsername(username);
        return orderService.add(order);
    }

    @PostMapping("/findOrderList")
    public PageResult<OrderListVo> findOrderList(int page, int size, String orderStatus, String username){
        return  orderService.findOrderList(page,size,username,orderStatus);
    }

    @PostMapping("/updateAddress")
    public Result updateAddress(@RequestBody Map map){
        orderService.updateAddress(map);
        return new Result(200,"修改成功","");
    }

    @PostMapping("/closeOrder")
    public Result closeOrder(@RequestBody Order order,String message){
        orderService.closeOrder(order,message);
        return new Result(200,"修改成功","");
    }
    @PostMapping("/determineOrder")
    public PageResult<Order> determineOrder(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  orderService.determineOrderList(searchMap,page,size);
    }

    @PostMapping("/orderMessage")
    public PageResult<Order> orderMessage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  orderService.orderMessage(searchMap,page,size);
    }

    @GetMapping("/orderMessage")
    public Result orderMessage(String orderId,String status){
        orderService.changeOrderStatus(orderId,status);
        return new Result(200,"修改成功","");
    }

    @GetMapping("/returnOrder2")
    public Result returnOrder2(String orderId,String type){
        orderService.returnOrder2(orderId,type);
        return new Result(200,"修改成功","");
    }
    /**
     * 获取统计图表数据
     * @return
     */
    @GetMapping("/getsum")
    public Map getsum(){
        return orderService.getsum();
    }


}
